// 1 - START DROPDOWN SLIDER SCRIPTS ------------------------------------------------------------------------
var clicked = false;
var clickedAccMenus = false;
var addNewItemSelected = false;
var viewAllItemsSelected = false;
var deleteItemsSelected = false;

$(document).ready(function () {
    // Register for showing and hidding sub menus
    registerShowSubMenus();
    registerHideSubMenus();

    // Highligh the function navigators
    registerHighlightNavsFunc();

    // Active function navigator
    activeFunctionNavigator();
});

// Show sub-menu items
function registerShowSubMenus() {
    $(".menu-items-inside").click(function () {
        if (clicked == false) {
            clicked = true;
            $(".account-content").slideToggle("fast");
        } else {
            clicked = false;
            $(".account-content").slideUp();
        }
        return false;
    });

    $(".showhide-account").click(function () {
        if (clickedAccMenus == false) {
            clickedAccMenus = true;
            $(".account-content-menu").slideToggle("fast");
        } else {
            clickedAccMenus = false;
            $(".account-content-menu").slideUp();
        }
        return false;
    });
}

// Hide sub-menu items
function registerHideSubMenus() {
    $(document).bind("click", function (e) {
        //alert(e.target.id);
        if (e.target.id != $(".menu-items-inside").attr("class")) {
            clicked = false;
            $(".account-content").slideUp();
            $(".select_sub").fadeIn('fast');
        }
    });

    $(document).bind("click", function (e) {
        //alert(e.target.id);
        if (e.target.id != $(".showhide-account").attr("class")) {
            clicked = false;
            $(".account-content-menu").slideUp();
        }
    });
}

// Highligh the function navigators
function registerHighlightNavsFunc() {
    registerHighlightAllItemsNav();
    registerHighlightAddNewItemNav();
    registerHighlightDeleteItemsNav();
}

// registerHighlight View All Items navigator
function registerHighlightAllItemsNav() {
    $("#view-all-items-left").mousemove(function () {
        if (viewAllItemsSelected)
            return;
        $("#view-all-items-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#view-all-items-right").removeClass("step-light-right").addClass("step-dark-right");
        $("#view-all-items-no").removeClass("step-no-off").addClass("step-no");
    });
    $("#view-all-items-left").mouseleave(function () {
        if (viewAllItemsSelected)
            return;
        $("#view-all-items-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#view-all-items-right").removeClass("step-dark-right").addClass("step-light-right");
        $("#view-all-items-no").removeClass("step-no").addClass("step-no-off");
    });
}

function highlightAllItemsNav(isHighLighted) {
    if (isHighLighted) {
        $("#view-all-items-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#view-all-items-right").removeClass("step-light-right").addClass("step-dark-right");
        $("#view-all-items-no").removeClass("step-no-off").addClass("step-no");
    } else {
        $("#view-all-items-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#view-all-items-right").removeClass("step-dark-right").addClass("step-light-right");
        $("#view-all-items-no").removeClass("step-no").addClass("step-no-off");
    }
}

// registerHighlight Add New Item navigator
function registerHighlightAddNewItemNav() {
    $("#add-new-item-left").mousemove(function () {
        if (addNewItemSelected)
            return;
        $("#add-new-item-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#add-new-item-right").removeClass("step-light-right").addClass("step-dark-right");
        $("#add-new-item-no").removeClass("step-no-off").addClass("step-no");
    });
    $("#add-new-item-left").mouseleave(function () {
        if (addNewItemSelected)
            return;
        $("#add-new-item-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#add-new-item-right").removeClass("step-dark-right").addClass("step-light-right");
        $("#add-new-item-no").removeClass("step-no").addClass("step-no-off");
    });
}

function highlightAddNewItemNav(isHighLighted) {
    if (isHighLighted) {
        $("#add-new-item-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#add-new-item-right").removeClass("step-light-right").addClass("step-dark-right");
        $("#add-new-item-no").removeClass("step-no-off").addClass("step-no");
    } else {
        $("#add-new-item-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#add-new-item-right").removeClass("step-dark-right").addClass("step-light-right");
        $("#add-new-item-no").removeClass("step-no").addClass("step-no-off");
    }
}

// registerHighlight Delete Items navigator
function registerHighlightDeleteItemsNav() {
    $("#delete-items-left").mousemove(function () {
        if (deleteItemsSelected)
            return;
        $("#delete-items-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#delete-items-right").removeClass("step-light-round").addClass("step-dark-round");
        $("#delete-items-no").removeClass("step-no-off").addClass("step-no");
    });
    $("#delete-items-left").mouseleave(function () {
        if (deleteItemsSelected)
            return;
        $("#delete-items-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#delete-items-right").removeClass("step-dark-round").addClass("step-light-round");
        $("#delete-items-no").removeClass("step-no").addClass("step-no-off");
    });
}

function highlightDeleteItemsNav(isHighLighted) {
    if (isHighLighted) {
        $("#delete-items-left").removeClass("step-light-left").addClass("step-dark-left");
        $("#delete-items-right").removeClass("step-light-round").addClass("step-dark-round");
        $("#delete-items-no").removeClass("step-no-off").addClass("step-no");
    } else {
        $("#delete-items-left").removeClass("step-dark-left").addClass("step-light-left");
        $("#delete-items-right").removeClass("step-dark-round").addClass("step-light-round");
        $("#delete-items-no").removeClass("step-no").addClass("step-no-off");
    }
}

// Active function navigator
function activeFunctionNavigator() {
    // Get all ref tags which is existed in step-holder
    var aElems = document.getElementById("step-holder").getElementsByTagName("a");
    // Get current reference
    var loc = window.location.href;
    var currentElem = "";
    for (var i = 0; i < aElems.length; i++) {
        if (aElems[i].href == loc) {
            currentElem = aElems[i].id;
            break;
        }
    }

    var activeRef = "";

    if (currentElem != "") {
        switch (currentElem) {
            case "view-all-items-ref":
                activeRef = "view";
                break;

            case "add-new-item-ref":
                activeRef = "add";
                break;

            case "delete-items-ref":
                activeRef = "delete";
                break;
        }
    } else {
        if (loc.indexOf("Insert") != -1) {
            activeRef = "add";
        } else if (loc.indexOf("DeleteRange") != -1) {
            activeRef = "delete";
        } else {
            activeRef = "view";
        }
    }

    // Start to highlight navs
    switch (activeRef) {
        case "view":
            highlightAllItemsNav(true);
            highlightAddNewItemNav(false);
            highlightDeleteItemsNav(false);
            viewAllItemsSelected = true
            addNewItemSelected = false;
            deleteItemsSelected = false;
            break;

        case ("add"):
            highlightAllItemsNav(false);
            highlightAddNewItemNav(true);
            highlightDeleteItemsNav(false);
            viewAllItemsSelected = false
            addNewItemSelected = true;
            deleteItemsSelected = false;
            break;

        case ("delete"):
            highlightAllItemsNav(false);
            highlightAddNewItemNav(false);
            highlightDeleteItemsNav(true);
            viewAllItemsSelected = false
            addNewItemSelected = false;
            deleteItemsSelected = true;
            break;
    }
}
